package com.csii.activiti.server.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csii.activiti.server.api.vo.Result;
import com.csii.activiti.server.core.entity.ActBatchDelegateTask;
import com.csii.activiti.server.core.entity.ActBatchOperation;
import com.csii.activiti.server.core.entity.ActFlowTodo;
import com.csii.activiti.server.core.query.QueryActFlowTask;
import com.csii.activiti.server.core.service.FlowManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(tags="流程管理")
@RestController
@RequestMapping("/${activity.basic.url:activiti}/flow/management")
@Slf4j
public class FlowManagementController {

    @Autowired
    private FlowManagementService flowManagementService;


    @ApiOperation("查询列表")
    @GetMapping("/queryList")
    public Result<Page<ActFlowTodo>> queryData(QueryActFlowTask queryActFlowTask,
                                               @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                               @RequestParam(name="pageSize", defaultValue="10") Integer pageSize){
        return Result.ok(flowManagementService.queryTaskList(queryActFlowTask,new Page(pageNo, pageSize)));
    }

    @ApiOperation("批量完成任务节点")
    @PostMapping("/batchCompleteTask")
    public Result batchCompleteTask(@RequestBody ActBatchOperation actBatchOperation){
        flowManagementService.batchCompleteTask(actBatchOperation);
        return Result.ok();
    }

    @ApiOperation("批量转交任务节点")
    @PostMapping("/batchDelegateTask")
    public Result batchDelegateTask(@RequestBody ActBatchDelegateTask batchDelegateTask){
        flowManagementService.batchDelegateTask(batchDelegateTask);
        return Result.ok();
    }

    @ApiOperation("批量驳回任务节点")
    @PostMapping("/batchBackTask")
    public Result batchBackTask(@RequestBody ActBatchOperation actBatchOperation){
        flowManagementService.batchBackTask(actBatchOperation);
        return Result.ok();
    }


}
